<template>


    <div class="page-box">
       <div class="page-title">
          {{ '库存调拨审核' }}
       </div>
 
       <div class="page-search">
          <div class="search-box flex_start_center" :style="{ height: IsHeight }">
             <el-input v-model="search" placeholder="调拨单号/调入仓库"
                style="width: 200px; margin-right: 10px; margin-bottom: 10px;" />
          </div>
 
          <div class="search-btn">
             <div class="btn_item" @click="handleClickHeight">
                <img class="btn_img" src="@/assets/sx.png" alt=""> <span> 高级筛选 </span>
             </div>
      
  
          </div>
 
       </div>
       <div class="search-btn-right">
       
       </div>
    </div>
 
    <div class="table-box">
 
       <el-table :data="tabeData" style="width: 100%" v-loading="loading" border
           default-expand-all    >
           <el-table-column align="center" prop="transfer_no" label="调拨单号" width="200">
            <template #default="scope">
              <div style="color: blue; cursor: pointer;" >
                {{ scope.row.transfer_no }}
              </div>
   
            </template>
          </el-table-column>

          <el-table-column align="center" prop="transfer_date" label="调拨日期" width="120" />
          <el-table-column align="center" prop="to_warehouse_name" label="调入仓库"  />
          
          <el-table-column align="center" prop="note" label="备注" min-width="180">
            <template #default="scope">
              <div >{{ scope.row.note }}</div>
            </template>
          </el-table-column>

          <el-table-column align="center" prop="creator_name" label="提交人" width="120" />
          <el-table-column align="center" prop="created_at" label="提交时间" width="180" />

          <el-table-column align="center" prop="phone" label="操作" width="120" >
            <template #default="scope">
                <el-button type="primary" size="small" @click="handleClickAudit(scope.row)">审核</el-button>
            </template>
          </el-table-column>

       </el-table>
    </div>
 
    <!-- 分页 -->
    <Pagination class="pagination" @pageSize="pageSize" @getPage="getPage" :page="pageData.page"
       :page-size="pageData.page_size" :total="total" />
        <examine v-model:dialogVisible="isShow" :dialogRow="dialogRow"  />
 </template>
 
 <script setup lang="ts">

 import { ref, onMounted, watch } from "vue";

 import Pagination from "@/components/Pagination.vue";
 import { ElMessageBox, ElMessage } from 'element-plus';
 import examine from "./components/InventoryReview/examine.vue";
 import api from "@/api";

 interface Warehouse {
    id: string | number;
    transfer_no: string; // 库存调拨单号
    transfer_date: string; // 调拨日期
    to_warehouse_id: number | string; // 拨入的仓库ID
    to_warehouse_name: string; // 拨入的仓库名称
    status: number; // 库存调拨状态，0: 待提交，1: 审核中，2: 审核完成，3: 审核拒绝
    note: string; // 备注
    creator_admin_id: string; // 创建人ID
    creator_name: string; // 创建人姓名
    submit_member_id: string; // 提交人ID
    submit_name: string; // 提交人姓名
    submit_time: string; // 提交时间
    audit_admin_id: string; // 审核人ID
    audit_name: string; // 审核人姓名
    audit_time: string; // 审核时间
    audit_opinion: string; // 审核意见
    created_at: string; // 创建时间
    updated_at: string; // 更新时间
 }

 let IsHeight = ref<number | string>(0);
 const isShow = ref<boolean>(false);
 const search = ref<string>('');
 let dialogRow = ref<Warehouse>({} as Warehouse);
 const pageData = ref({
    page_size: 10,
    page: 1,
    house_type: "",
    category: "",
    keywords: "",
 });
 const total = ref(0);
 const tabeData = ref<Warehouse[]>([]);
 // 侦听动态分页
 watch(
    () => {
       return pageData.value;
    },
    () => {
       getAlltabeData();
    },
    { deep: true }
 );
 
 // 搜索关键词监听
 watch(
    () => search.value,
    (newVal) => {
       pageData.value.keywords = newVal;
       pageData.value.page = 1;
    }
 );

 
 let nub = ref<number>(0);
 const handleClickHeight = () => {
    nub.value++;
    if (nub.value % 2 == 1) {
       IsHeight.value = '34px';
    } else {
       IsHeight.value = '0px';
    }
 }
 
 const pageSize = (e: number) => {
    pageData.value.page_size = e;
    getAlltabeData();
 }
 const getPage = (e: number) => {
    pageData.value.page = e;
    getAlltabeData();
 }
 onMounted(() => {
    getAlltabeData();
 })
 
 // 设置行样式

 // 获取仓库列表
 const getAlltabeData = async () => {
    loading.value = true;
    try {
      const res = await api.product.stock_transfer_list({
        ...pageData.value,
      });
      if (res.code === 200) {
        tabeData.value = res.data.data;
        total.value = res.data.pager.total_records;
      }

    } catch (error) {
      console.error('获取仓库列表失败', error);
    } finally {
      loading.value = false;
    }
 };
 
 const loading = ref(false);
 

 // 提交表单回调
 const handleSubmit = () => {
    getAlltabeData();
 }

const handleClickAudit = async (row: Warehouse) => {
   isShow.value = true;
   const res = await api.product.stock_transfer_detail({
    id: row.id,
   });
   if (res.code === 200) {
    dialogRow.value = res.data;
    console.log(dialogRow.value);
   }
}
 
 </script>
 
 <style lang="scss" scoped>
 .btn-box {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
 }
 
 .main-warehouse {
    font-weight: bold;
    color: #333;
 }
 
 // 输入框样式
 :deep(.el-input__wrapper) {
    background-color: rgba(250, 252, 251, 1);
 }
 
 //表格样式
 :deep(.el-table) {
    --el-table-header-bg-color: rgba(235, 236, 240, 1);
 }
 
 :deep(.el-table thead) {
    color: #444;
 }
 
 // 子仓库行样式
 :deep(.sub-warehouse-row) {
    background-color: #fef6e5;
 }
 
 //分页样式
 .pagination {
    width: calc(100% - 250px);
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding-top: 10px;
    border-top: 1px solid #98989848;
 }
 
 :deep(.el-pagination.is-background .el-pager li.is-active) {
    background-color: #000 !important;
 }
 </style>
 